import {
  createRouter,
  createWebHashHistory
} from 'vue-router'


const routes = [{
    path: '/',
    name: "Home",
    component: () => import('../views/Layout.vue'),
    meta: {
      title: '小兔鲜'
    },
    children: [{
        path: "/",
        name: "Index",
        meta: {
          title: '小兔鲜'
        },
        component: () => import('../views/home')
      },
      {
        path: "/category/:id",
        name: "Category",
        component: () => import('../views/category/category.vue')
      },
      {
        path: "/category/sub/:id",
        name: "CategorySub",
        component: () => import("../views/category/CategorySub.vue")
      }, {
        path: '/product/:id',
        name: "Product",
        component: () => import('../views/goods')
      }, {
        path: "/cart",
        name: "Cart",
        component: () => import("../views/Cart")
      }
    ]
  }, {
    path: "/login",
    name: "Login",
    component: () => import("../views/Login.vue")
  }

]

const router = createRouter({
  history: createWebHashHistory(),
  routes
})
router.beforeEach((to, from) => {
  document.title = '小兔鲜儿-新鲜 惠民 快捷!'
  // window.scrollTo({
  //   top: 0,
  //   behavior: 'smooth'
  // })
  // let token = localStorage.getItem('token')
  // if (!token) {
  //   next('/login')
  //   // return '/login'
  // } else {
  //   return false
  // }
})

export default router